package teaching.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import teaching.mapper.CourseMapper;
import teaching.mapper.CourseStudentMapper;
import teaching.mapper.StudentMapper;
import teaching.pojo.CourseStudent;
import teaching.pojo.Student;

import javax.annotation.Resource;
import java.util.*;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/3/9
 * Description:
 */
@Service
public class CourseStudentService {
    @Resource
    private CourseStudentMapper courseStudentMapper;
    @Resource
    private CourseMapper courseMapper;
    @Autowired
    private StudentMapper studentMapper;


    public List<Student> listByCourse(Long cid) {
        List<CourseStudent> studentIdList = courseStudentMapper.listByCourse(cid);
        System.out.println("学生id列表" + studentIdList);
        //根据得到的学生的id得到学生表里的学生信息
        List<Student> studentList = new ArrayList<>();
        for (CourseStudent courseStudent : studentIdList) {
            Long studentId = courseStudent.getStudentId();
            studentList.add(studentMapper.findById(studentId));
        }
        return studentList;
    }
}
